<?php
/**
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: PlayerController.php 1079 2011-12-07 03:31:00Z mmxie $
 */
class Api_PlayerController extends IG_Controller_Action
{
    public function maxLevelAction()
    {
        $failed = array(
            'rv' => -2
        );
        if (!($user = $this->_getParam('user'))) {
            $this->_helper->json($failed);
        }

        try {
            $maxLevelRole = new Game_Model_MaxLevelRole();
            $data = $maxLevelRole->getRoleByUser($user);
        } catch (Exception $e) {
            $this->_helper->json($failed+array('message' => '系统错误'));
        }

        if ($data) {
            $this->_helper->json(array(
                'rv'   => 0,
                'body' => array(
                    'playerid'       => $data['role_id'],
                    'level'          => $data['level'],
                    'sid'            => $data['server'],
                    'rolename'       => iconv('gbk', 'utf-8', $data['role_name']),
                    'lastUpdateTime' => $data['update_time'],
                ),
            ));
        } else {
            $this->_helper->json(array(
                'rv' => -1
            ));
        }
    }
}